//==============================================================================================
/**
 * @file	syoujyou.c
 * @brief	表彰状（図鑑コンプリート）
 * @author	hosaka genya(GS)
 * @date
 */
//==============================================================================================
#include "common.h"

#include "system/procsys.h"
#include "system/arc_util.h"
#include "savedata/savedata_def.h"

#include "system/lib_pack.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/fontproc.h"
#include "system/pm_str.h"
#include "system/wipe.h"
#include "system/snd_tool.h"
#include "system/wordset.h"
#include "system/main.h"

#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/gra_tool.h"

#include "poketool/pokeparty.h"

#include "field/pair_poke_idx.h"

#include "field/script_def.h"
#include "syoujyou_def.h"

#include "msgdata/msg.naix"
#include "msgdata/msg_award.h"

#include "application/pst2_gra.naix"
#include "data/mmodel/mmodel.naix"
#include "syoujyou.naix"

#include "../../field/scr_tool.h"

#include "demo\syoujyou.h"

//@@@ 後ほど、正式な構造体が切られる予定
typedef struct
{
	u8 FootType;
	u8 BigSize;
	u8 FlyFlg;
	u8 RoomFlg;
}DEBUG_POKE_INFO;

//================================================================
//================================================================
//
//
//
//
//
//================================================================
//----------------------------------
//定数宣言
//----------------------------------
// ＰＲＯＣメインシーケンス
enum {
	SYOUJYOU_SEQ_INIT = 0,
	SYOUJYOU_SEQ_DISPON,
	SYOUJYOU_SEQ_WAIT,
	SYOUJYOU_SEQ_SCROLL,
	SYOUJYOU_SEQ_MAIN,
	SYOUJYOU_SEQ_EXIT,
};

//----------------------------------
//型宣言
//----------------------------------
///	制御用ワーク構造体
typedef struct SYOUJYOU_WORK_tag
{
	int					heapID;
	int					type;
	SAVEDATA*			savedata;
	MYSTATUS*			my;
	POKEMON_PARAM*		poke;	///< 連れ歩いてるポケモンの情報

	//ＢＧシステム関連
	GF_BGL_INI*			bgl;
	GF_BGL_BMPWIN		msgwin_m;
	GF_BGL_BMPWIN		msgwin_s;
	MSGDATA_MANAGER*	msgman;
	WORDSET*			wordset;

	//スクロール
	s16					scroll;
	u16					wait;

	// OBJシステム関連
	CATS_SYS_PTR csp;
	CATS_RES_PTR crp;
	CATS_ACT_PTR cap[ CAP_ID_MAX ];
	int BigSize;

}SYOUJYOU_WORK;

//----------------------------------
//外部関数定義
//----------------------------------
extern void	Main_SetNextProc(FSOverlayID ov_id, const PROC_DATA * proc_data);

//----------------------------------
//関数宣言
//----------------------------------
PROC_RESULT Syoujyou_Init( PROC * proc, int * seq );
PROC_RESULT Syoujyou_Main( PROC * proc, int * seq );
PROC_RESULT Syoujyou_Exit( PROC * proc, int * seq );

static void Syoujyou_VBlank( void* work );

static void Syoujyou_VramBankSet( SYOUJYOU_WORK* wk );
static void Syoujyou_VramBankRelease( SYOUJYOU_WORK* wk );
static void Syoujyou_MsgDataSet( SYOUJYOU_WORK* wk );
static void Syoujyou_MsgDataRelease( SYOUJYOU_WORK* wk );

static void Syoujyou_ScrollInit( SYOUJYOU_WORK* wk );
static void Syoujyou_ScrollSet( SYOUJYOU_WORK* wk );
static void Syoujyou_GraphicLoad( SYOUJYOU_WORK* wk );
static void Syoujyou_MsgPrint( SYOUJYOU_WORK* wk );

static CATS_ACT_PTR OBJ_AddStatus( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, u8 pri );
static CATS_ACT_PTR OBJ_AddPoke( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 px, s16 py );
static CATS_ACT_PTR OBJ_AddHero( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 px, s16 py );
static void OBJ_Init( SYOUJYOU_WORK* wk );
static void OBJ_Delete( SYOUJYOU_WORK* wk );
static void OBJ_LoadRes( SYOUJYOU_WORK* wk );
static void OBJ_ScrollSet( SYOUJYOU_WORK* wk );
static void OBJ_CgxChangeTransShiftVramOfs( CLACT_WORK_PTR act, u8 * buf, u32 siz, u32 VramOfs );
static void CLACT_MapModelTrans( CLACT_WORK_PTR act, u32 tex_idx, u8 ptn_ofs, HEAPID HeapID );
static void CLACT_HeroTrans( CLACT_WORK_PTR act, MYSTATUS* my, HEAPID heapID );
static void OBJ_PokeTrans( CLACT_WORK_PTR act, POKEMON_PARAM* poke, HEAPID HeapID, BOOL b_bigsize );

//----------------------------------
//マクロ宣言
//----------------------------------
#define KEYTRG( pattern )	( ( sys.trg & ( pattern ) ) == ( pattern ) )
#define KEYCNT( pattern )	( ( sys.cont & ( pattern ) ) == ( pattern ) )

#define FADE( pattern, col, heapID ) {						\
	WIPE_SYS_Start(	WIPE_PATTERN_WMS,pattern,pattern,col,	\
					WIPE_DEF_DIV,WIPE_DEF_SYNC,heapID);		\
}

#define FRAME_ON( frame )		{ GF_BGL_VisibleSet( frame, VISIBLE_ON ); }
#define FRAME_OFF( frame )		{ GF_BGL_VisibleSet( frame, VISIBLE_OFF ); }
#define FRAME_ALLOFF {				\
	FRAME_OFF( GF_BGL_FRAME0_M )	\
	FRAME_OFF( GF_BGL_FRAME1_M )	\
	FRAME_OFF( GF_BGL_FRAME2_M )	\
	FRAME_OFF( GF_BGL_FRAME3_M )	\
	FRAME_OFF( GF_BGL_FRAME0_S )	\
	FRAME_OFF( GF_BGL_FRAME1_S )	\
	FRAME_OFF( GF_BGL_FRAME2_S )	\
	FRAME_OFF( GF_BGL_FRAME3_S )	\
}

//ＢＧコントロール定数
#define SYOUJYOU_TEXT_M_FRAME	(GF_BGL_FRAME0_M)
#define SYOUJYOU_SYOU_M_FRAME	(GF_BGL_FRAME1_M)
#define SYOUJYOU_BACK_M_FRAME	(GF_BGL_FRAME3_M)

#define SYOUJYOU_TEXT_S_FRAME	(GF_BGL_FRAME0_S)
#define SYOUJYOU_SYOU_S_FRAME	(GF_BGL_FRAME1_S)
#define SYOUJYOU_BACK_S_FRAME	(GF_BGL_FRAME3_S)

//=================================================================================================
//
// ＰＲＯＣ定義テーブル
//
//=================================================================================================
const PROC_DATA SyoujyouProcData = {
	Syoujyou_Init,
	Syoujyou_Main,
	Syoujyou_Exit,
	NO_OVERLAY_ID
};

//================================================================
//----------------------------------
//ＰＲＯＣ初期化
//----------------------------------
PROC_RESULT Syoujyou_Init( PROC* proc, int* seq )
{
	SYOUJYOU_WORK* wk;
	int	heapID = HEAPID_SYOUJYOU;

	sys_CreateHeap( HEAPID_BASE_APP, heapID, 0x20000 );

	wk = PROC_AllocWork( proc, sizeof( SYOUJYOU_WORK ), heapID );
	memset( wk, 0, sizeof( SYOUJYOU_WORK ) );

	{
		SYOUJYOU_INI* ini = (SYOUJYOU_INI*)PROC_GetParentWork( proc );
		POKEPARTY* party;
		int idx = GetFrontPokemon2( ini->savedata );

		GF_ASSERT(ini);
		GF_ASSERT(ini->savedata);

		party = SaveData_GetTemotiPokemon(ini->savedata);

		wk->heapID		= heapID;
		wk->savedata	= ini->savedata;
		wk->type		= ini->type;
		wk->my			= SaveData_GetMyStatus(wk->savedata);
		wk->poke		= PokeParty_GetMemberPointer(party, idx);
	}

	WIPE_SetBrightness( WIPE_DISP_MAIN,WIPE_FADE_BLACK );
	WIPE_SetBrightness( WIPE_DISP_SUB,WIPE_FADE_BLACK );

	sys_VBlankFuncChange( NULL, NULL );	// VBlankセット
	sys_HBlankIntrSet( NULL,NULL );		// HBlankセット

	GF_Disp_GX_VisibleControlInit();
	GF_Disp_GXS_VisibleControlInit();
	GX_SetVisiblePlane(0);
	GXS_SetVisiblePlane(0);
	sys_KeyRepeatSpeedSet( SYS_KEYREPEAT_SPEED_DEF, SYS_KEYREPEAT_WAIT_DEF );

	Syoujyou_VramBankSet( wk );
	Syoujyou_MsgDataSet( wk );
	sys_VBlankFuncChange( Syoujyou_VBlank, (void*)wk );

	if( wk->type == SYOUJYOU_TYPE_PAIR )
	{
		OBJ_Init( wk );
		OBJ_LoadRes( wk );
	}

	GF_Disp_DispOn();

	return	PROC_RES_FINISH;
}

//----------------------------------
//ＰＲＯＣメイン
//----------------------------------
PROC_RESULT Syoujyou_Main( PROC* proc, int* seq )
{
	SYOUJYOU_WORK* wk = PROC_GetWork( proc );
	PROC_RESULT result = PROC_RES_CONTINUE;

	switch( *seq ){
	// 画面初期化
	case SYOUJYOU_SEQ_INIT:

		Syoujyou_ScrollInit( wk );
		Syoujyou_GraphicLoad( wk );
		Syoujyou_MsgPrint( wk );

		FRAME_ON( SYOUJYOU_TEXT_M_FRAME );
		FRAME_ON( SYOUJYOU_SYOU_M_FRAME );
		FRAME_ON( SYOUJYOU_BACK_M_FRAME );
		FRAME_ON( SYOUJYOU_TEXT_S_FRAME );
		FRAME_ON( SYOUJYOU_SYOU_S_FRAME );
		FRAME_ON( SYOUJYOU_BACK_S_FRAME );
		FADE( WIPE_TYPE_FADEIN, WIPE_FADE_BLACK, wk->heapID )
		*seq = SYOUJYOU_SEQ_DISPON;
		break;

	// ディスプレイ反映
	case SYOUJYOU_SEQ_DISPON:
		if(WIPE_SYS_EndCheck() == TRUE){
			wk->wait = 0;
			*seq = SYOUJYOU_SEQ_WAIT;
		}
		break;

	// 開始ウェイト
	case SYOUJYOU_SEQ_WAIT:
		if( wk->wait < 60 ){
			wk->wait++;
		} else {
			*seq = SYOUJYOU_SEQ_SCROLL;
		}
		break;

	// 開始ウェイト
	case SYOUJYOU_SEQ_SCROLL:
		if( ( wk->scroll > -8*24 )){
			wk->scroll -= 4;
			Syoujyou_ScrollSet( wk );
		} else {
			wk->scroll = -8*24;
			Syoujyou_ScrollSet( wk );
			*seq = SYOUJYOU_SEQ_MAIN;
		}
		break;

	// メインループ
	case SYOUJYOU_SEQ_MAIN:
		if( (KEYTRG( PAD_BUTTON_A ))||(KEYTRG( PAD_BUTTON_B ))||( sys.tp_trg ) ){
			FADE( WIPE_TYPE_FADEOUT, WIPE_FADE_BLACK, wk->heapID )
			*seq = SYOUJYOU_SEQ_EXIT;
		}
#if 0
		if( KEYCNT( PAD_KEY_UP ) && ( wk->scroll < 0 )){
			wk->scroll += 4;
			Syoujyou_ScrollSet( wk );
		}
		if( KEYCNT( PAD_KEY_DOWN ) && ( wk->scroll > -8*24 )){
			wk->scroll -= 4;
			Syoujyou_ScrollSet( wk );
		}
#endif
		break;

	// 終了
	case SYOUJYOU_SEQ_EXIT:
		if(WIPE_SYS_EndCheck() == TRUE){
			result = PROC_RES_FINISH;
		}
		break;
	}
	return result;
}

//----------------------------------
//ＰＲＯＣ終了
//----------------------------------
PROC_RESULT Syoujyou_Exit( PROC* proc, int* seq )
{
	SYOUJYOU_WORK* wk = PROC_GetWork( proc );
	int heapID = wk->heapID;

	if( wk->type == SYOUJYOU_TYPE_PAIR )
	{
		OBJ_Delete( wk );
	}

	Syoujyou_MsgDataRelease( wk );
	Syoujyou_VramBankRelease( wk );
	sys_VBlankFuncChange( NULL, NULL );

	PROC_FreeWork( proc );
	sys_DeleteHeap( heapID );

	return	PROC_RES_FINISH;
}


//----------------------------------
//ＶＢＬＡＮＫ関数
//----------------------------------
static void Syoujyou_VBlank( void* work )
{
	SYOUJYOU_WORK* wk = work;

	GF_ASSERT(wk);
	GF_ASSERT(wk->bgl);

	if( wk->type == SYOUJYOU_TYPE_PAIR ) {
		GF_ASSERT( wk->crp );
		CATS_Draw( wk->crp );
		CATS_RenderOamTrans();
	}

	GF_BGL_VBlankFunc(wk->bgl);

	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}


//----------------------------------
//ＶＲＡＭ設定
//----------------------------------
#define PALSIZE			( 2*16 )

// パレット設定(メインサブ画面共通)
#define SYOUJYOU_BACKPLT_NUM	( 0 )			//背景
#define SYOUJYOU_SYOUPLT_NUM	( 1 )			//賞状
#define SYOUJYOU_TEXTPLT_NUM	( 2 )			//メッセージ

#define BGCONTSET( frame, scr, cgx, scrsiz, bufsiz ){					\
	header.screenBase		= scr;										\
	header.charBase			= cgx;										\
	header.scrbufferSiz		= bufsiz;									\
	header.screenSize		= scrsiz;									\
	GF_BGL_BGControlSet( wk->bgl, frame, &header, GF_BGL_MODE_TEXT );	\
	GF_BGL_ScrClear( wk->bgl, frame );									\
}

static void Syoujyou_VramBankSet( SYOUJYOU_WORK* wk )
{
	{ //ＶＲＡＭ設定
		GF_BGL_DISPVRAM vramSetTable = {
			GX_VRAM_BG_128_B,				// メイン2DエンジンのBG
			GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット
			GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG(メインと共通)
			GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット
			GX_VRAM_OBJ_128_A,				// メイン2DエンジンのOBJ
			GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット
			GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
			GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット
			GX_VRAM_TEX_NONE,				// テクスチャイメージスロット
			GX_VRAM_TEXPLTT_NONE			// テクスチャパレットスロット
		};
		GF_Disp_SetBank( &vramSetTable );
	}

	{ //ＢＧライブラリ用メモリ確保
		wk->bgl = GF_BGL_BglIniAlloc(wk->heapID);
	}

	{ // ＢＧシステム設定
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG( &BGsys_data );
	}
	{ // ＢＧシステム設定
		GF_BGL_BGCNT_HEADER header = {	0, 0, 0, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
										0, 0, GX_BG_EXTPLTT_01, 0, 0, 0, FALSE };
		// メインＢＧシステム設定
		// テキストＢＧ設定(BG0)
		BGCONTSET(	SYOUJYOU_TEXT_M_FRAME, GX_BG_SCRBASE_0x0000, GX_BG_CHARBASE_0x10000,
					GF_BGL_SCRSIZ_256x512, 0x1000 )
		// 賞状ＢＧ設定(BG1)
		BGCONTSET(	SYOUJYOU_SYOU_M_FRAME, GX_BG_SCRBASE_0x1000, GX_BG_CHARBASE_0x08000,
					GF_BGL_SCRSIZ_256x512, 0x1000 )
		// 背景ＢＧ設定(BG3)
		BGCONTSET(	SYOUJYOU_BACK_M_FRAME, GX_BG_SCRBASE_0x2000, GX_BG_CHARBASE_0x04000,
					GF_BGL_SCRSIZ_256x256, 0x0800 )

		// サブＢＧシステム設定
		// テキストＢＧ設定(BG0)
		BGCONTSET(	SYOUJYOU_TEXT_S_FRAME, GX_BG_SCRBASE_0x0000, GX_BG_CHARBASE_0x10000,
					GF_BGL_SCRSIZ_256x512, 0x1000 )
		// 賞状ＢＧ設定(BG1)
		BGCONTSET(	SYOUJYOU_SYOU_S_FRAME, GX_BG_SCRBASE_0x1000, GX_BG_CHARBASE_0x08000,
					GF_BGL_SCRSIZ_256x512, 0x1000 )
		// 背景ＢＧ設定(BG3)
		BGCONTSET(	SYOUJYOU_BACK_S_FRAME, GX_BG_SCRBASE_0x2000, GX_BG_CHARBASE_0x04000,
					GF_BGL_SCRSIZ_256x256, 0x800 )
	}
	FRAME_ALLOFF
}

static void Syoujyou_VramBankRelease( SYOUJYOU_WORK* wk )
{
	FRAME_ALLOFF

	GF_BGL_BGControlExit( wk->bgl, SYOUJYOU_TEXT_M_FRAME );
	GF_BGL_BGControlExit( wk->bgl, SYOUJYOU_SYOU_M_FRAME );
	GF_BGL_BGControlExit( wk->bgl, SYOUJYOU_BACK_M_FRAME );
	GF_BGL_BGControlExit( wk->bgl, SYOUJYOU_TEXT_S_FRAME );
	GF_BGL_BGControlExit( wk->bgl, SYOUJYOU_SYOU_S_FRAME );
	GF_BGL_BGControlExit( wk->bgl, SYOUJYOU_BACK_S_FRAME );

	sys_FreeMemoryEz( wk->bgl );
}


//----------------------------------
//メッセージ設定
//----------------------------------
#define	SYOUJYOU_TEXT_WIN_PX		(0)
#define	SYOUJYOU_TEXT_WIN_PY		(0)
#define	SYOUJYOU_TEXT_WIN_SX		(32)
#define	SYOUJYOU_TEXT_WIN_SY		(24)
#define	SYOUJYOU_TEXT_WIN_PAL		( SYOUJYOU_TEXTPLT_NUM )
#define	SYOUJYOU_TEXT_WIN_CGX		(1)

#define DOTSIZE						(8)

static void Syoujyou_MsgDataSet( SYOUJYOU_WORK* wk )
{
	BMPWIN_DAT text_windata = { 0,SYOUJYOU_TEXT_WIN_PX,SYOUJYOU_TEXT_WIN_PY,
		SYOUJYOU_TEXT_WIN_SX,SYOUJYOU_TEXT_WIN_SY,SYOUJYOU_TEXT_WIN_PAL,SYOUJYOU_TEXT_WIN_CGX };

	MSG_PrintInit();											//メッセージ表示システム初期化
	wk->msgman = MSGMAN_Create									//メッセージデータ読み込み
		( MSGMAN_TYPE_DIRECT, ARC_MSG,NARC_msg_award_dat, wk->heapID );
	wk->wordset = WORDSET_Create( wk->heapID );					//ワードセット作成

	text_windata.frm_num = SYOUJYOU_TEXT_M_FRAME;
	GF_BGL_BmpWinAddEx( wk->bgl, &wk->msgwin_m, &text_windata );	//ビットマップ作成
	GF_BGL_BmpWinFill(&wk->msgwin_m,FBMP_COL_NULL,0,0,			//ビットマップ初期クリア
			SYOUJYOU_TEXT_WIN_SX * DOTSIZE, SYOUJYOU_TEXT_WIN_SY * DOTSIZE );
	text_windata.frm_num = SYOUJYOU_TEXT_S_FRAME;
	GF_BGL_BmpWinAddEx( wk->bgl, &wk->msgwin_s, &text_windata );	//ビットマップ作成
	GF_BGL_BmpWinFill(&wk->msgwin_s,FBMP_COL_NULL,0,0,			//ビットマップ初期クリア
			SYOUJYOU_TEXT_WIN_SX * DOTSIZE, SYOUJYOU_TEXT_WIN_SY * DOTSIZE );
}

static void Syoujyou_MsgDataRelease( SYOUJYOU_WORK* wk )
{
	GF_BGL_BmpWinDel( &wk->msgwin_s );	//ビットマップ破棄
	GF_BGL_BmpWinDel( &wk->msgwin_m );	//ビットマップ破棄

	WORDSET_Delete( wk->wordset );		//ワードセット破棄
	MSGMAN_Delete(wk->msgman);			//メッセージデータ破棄
}


//----------------------------------
//スクロール設定
//----------------------------------
#define SUBBG_OFFS ( 8*24 )
static void Syoujyou_ScrollInit( SYOUJYOU_WORK* wk )
{
	wk->scroll = 0;
	Syoujyou_ScrollSet( wk );
}

static void Syoujyou_ScrollSet( SYOUJYOU_WORK* wk )
{
	GF_BGL_ScrollReq( wk->bgl, SYOUJYOU_SYOU_M_FRAME, GF_BGL_SCROLL_Y_SET, wk->scroll );
	GF_BGL_ScrollReq( wk->bgl, SYOUJYOU_SYOU_S_FRAME, GF_BGL_SCROLL_Y_SET, wk->scroll+SUBBG_OFFS );
	GF_BGL_ScrollReq( wk->bgl, SYOUJYOU_TEXT_M_FRAME, GF_BGL_SCROLL_Y_SET, wk->scroll );
	GF_BGL_ScrollReq( wk->bgl, SYOUJYOU_TEXT_S_FRAME, GF_BGL_SCROLL_Y_SET, wk->scroll+SUBBG_OFFS );

	if( wk->type == SYOUJYOU_TYPE_PAIR ) {
		OBJ_ScrollSet( wk );
	}
}


//----------------------------------
//グラフィック読み込み
//----------------------------------
static void Syoujyou_GraphicLoad( SYOUJYOU_WORK* wk )
{
	int back_scrID, back_cgxID, back_palID;
	int syou_scrID, syou_cgxID, syou_palID;

	if( wk->type == SYOUJYOU_TYPE_JHOTO ){
	//シンオウ
		back_scrID = NARC_syoujyou_syoujyou_s_bg_NSCR;
		back_cgxID = NARC_syoujyou_syoujyou_s_bg_NCGR;
		back_palID = NARC_syoujyou_syoujyou_s_bg_NCLR;
		syou_scrID = NARC_syoujyou_dp_syoujyou_s_NSCR;
		syou_cgxID = NARC_syoujyou_dp_syoujyou_s_NCGR;
		syou_palID = NARC_syoujyou_dp_syoujyou_s_NCLR;
	} else if( wk->type == SYOUJYOU_TYPE_ZENKOKU ){
		//全国
		back_scrID = NARC_syoujyou_syoujyou_z_bg_NSCR;
		back_cgxID = NARC_syoujyou_syoujyou_z_bg_NCGR;
		back_palID = NARC_syoujyou_syoujyou_z_bg_NCLR;
		syou_scrID = NARC_syoujyou_dp_syoujyou_z_NSCR;
		syou_cgxID = NARC_syoujyou_dp_syoujyou_z_NCGR;
		syou_palID = NARC_syoujyou_dp_syoujyou_z_NCLR;
	} else {
		//つれあるき
		back_scrID = NARC_syoujyou_syoujyou_p_bg_NSCR;
		back_cgxID = NARC_syoujyou_syoujyou_p_bg_NCGR;
		back_palID = NARC_syoujyou_syoujyou_p_bg_NCLR;
		syou_scrID = NARC_syoujyou_gs_syoujyou_p_NSCR;
		syou_cgxID = NARC_syoujyou_gs_syoujyou_p_NCGR;
		syou_palID = NARC_syoujyou_gs_syoujyou_p_NCLR;
	}
	//背景
	ArcUtil_ScrnSet(	ARC_SYOUJYOU, back_scrID, wk->bgl,
						SYOUJYOU_BACK_M_FRAME, 0, 0, 0, wk->heapID );
	ArcUtil_BgCharSet(	ARC_SYOUJYOU, back_cgxID, wk->bgl,
						SYOUJYOU_BACK_M_FRAME, 0, 0, 0, wk->heapID );
	ArcUtil_PalSet(		ARC_SYOUJYOU, back_palID, PALTYPE_MAIN_BG,
						SYOUJYOU_BACKPLT_NUM * PALSIZE, PALSIZE, wk->heapID );
	ArcUtil_ScrnSet(	ARC_SYOUJYOU, back_scrID, wk->bgl,
						SYOUJYOU_BACK_S_FRAME, 0, 0, 0, wk->heapID );
	ArcUtil_BgCharSet(	ARC_SYOUJYOU, back_cgxID, wk->bgl,
						SYOUJYOU_BACK_S_FRAME, 0, 0, 0, wk->heapID );
	ArcUtil_PalSet(		ARC_SYOUJYOU, back_palID, PALTYPE_SUB_BG,
						SYOUJYOU_BACKPLT_NUM * PALSIZE, PALSIZE, wk->heapID );
	//賞状
	ArcUtil_ScrnSet(	ARC_SYOUJYOU, syou_scrID, wk->bgl,
						SYOUJYOU_SYOU_M_FRAME, 0, 0, 0, wk->heapID );
	GF_BGL_ScrPalChange( wk->bgl, SYOUJYOU_SYOU_M_FRAME, 0, 0, 32, 24, SYOUJYOU_SYOUPLT_NUM );
	GF_BGL_LoadScreenReq( wk->bgl, SYOUJYOU_SYOU_M_FRAME );
	ArcUtil_BgCharSet(	ARC_SYOUJYOU, syou_cgxID, wk->bgl,
						SYOUJYOU_SYOU_M_FRAME, 0, 0, 0, wk->heapID );
	ArcUtil_PalSet(		ARC_SYOUJYOU, syou_palID, PALTYPE_MAIN_BG,
						SYOUJYOU_SYOUPLT_NUM * PALSIZE, PALSIZE, wk->heapID );
	ArcUtil_ScrnSet(	ARC_SYOUJYOU, syou_scrID, wk->bgl,
						SYOUJYOU_SYOU_S_FRAME, 0, 0, 0, wk->heapID );
	GF_BGL_ScrPalChange( wk->bgl, SYOUJYOU_SYOU_S_FRAME, 0, 0, 32, 24, SYOUJYOU_SYOUPLT_NUM );
	GF_BGL_LoadScreenReq( wk->bgl, SYOUJYOU_SYOU_S_FRAME );
	ArcUtil_BgCharSet(	ARC_SYOUJYOU, syou_cgxID, wk->bgl,
						SYOUJYOU_SYOU_S_FRAME, 0, 0, 0, wk->heapID );
	ArcUtil_PalSet(		ARC_SYOUJYOU, syou_palID, PALTYPE_SUB_BG,
						SYOUJYOU_SYOUPLT_NUM * PALSIZE, PALSIZE, wk->heapID );
	//テキスト（NULLキャラ設定）
	GF_BGL_ClearCharSet( SYOUJYOU_TEXT_M_FRAME, 32, 0, wk->heapID );
	GF_BGL_ClearCharSet( SYOUJYOU_TEXT_S_FRAME, 32, 0, wk->heapID );
	//フォントパレット読み込み（システム）
	SystemFontPaletteLoad( PALTYPE_MAIN_BG, SYOUJYOU_TEXTPLT_NUM * PALSIZE, wk->heapID );
	SystemFontPaletteLoad( PALTYPE_SUB_BG, SYOUJYOU_TEXTPLT_NUM * PALSIZE, wk->heapID );
}


//----------------------------------
//メッセージ表示
//----------------------------------
#define SYOUJYOU_STRBUF_SIZE		(0x200)	//メッセージバッファサイズ

#include "poketool/poke_tool.h"
static void Syoujyou_MsgPrint( SYOUJYOU_WORK* wk )
{
	STRBUF* msg_str = STRBUF_Create( SYOUJYOU_STRBUF_SIZE, wk->heapID );

	int header_x;
	int header_y;
	int text_x;
	int text_y;

	if( wk->type == SYOUJYOU_TYPE_PAIR ) {
		header_x = 0;
		header_y = 4*8 + 4;
		text_x = 0;
		text_y = 56;
	}else{
		header_x = 48;
		header_y = 32;
		text_x = 64;
		text_y = 64;
	}

	{//名前の表示
		STRBUF* msg_tmp = STRBUF_Create( SYOUJYOU_STRBUF_SIZE, wk->heapID );

		// つれあるき
		if( wk->type == SYOUJYOU_TYPE_PAIR )
		{
			// ニックネームをレジスト
			POKEMON_PASO_PARAM* ppp;

			GF_ASSERT(wk->poke);

			ppp = PPPPointerGet(wk->poke);

			MSGMAN_GetString( wk->msgman, msg_pair_header, msg_tmp );
			WORDSET_RegisterPokeNickName( wk->wordset, 1, ppp );
		}
		else
		{
			MSGMAN_GetString( wk->msgman, msg_l02r0301_award_01, msg_tmp );
		}

		// トレーナー名をレジスト
		WORDSET_RegisterPlayerName( wk->wordset, 0, wk->my );


		WORDSET_ExpandStr( wk->wordset, msg_str, msg_tmp );
		GF_STR_PrintColor(	&wk->msgwin_m, FONT_SYSTEM, msg_str, header_x, header_y, MSG_ALLPUT,
							GF_PRINTCOLOR_MAKE(1, 2, 0), NULL );
		GF_STR_PrintColor(	&wk->msgwin_s, FONT_SYSTEM, msg_str, header_x, header_y, MSG_ALLPUT,
							GF_PRINTCOLOR_MAKE(1, 2, 0), NULL );
		STRBUF_Delete( msg_tmp );
	}

	{//本文の表示
		int		msgID;

		if( wk->type == SYOUJYOU_TYPE_JHOTO ){
			msgID = msg_l02r0301_award_02;
		} else if( wk->type == SYOUJYOU_TYPE_ZENKOKU ){
			msgID = msg_l02r0301_award_03;
		} else {
			msgID = msg_pair_text;
		}

		MSGMAN_GetString( wk->msgman, msgID, msg_str );
		GF_STR_PrintColor(	&wk->msgwin_m, FONT_SYSTEM, msg_str, text_x, text_y, MSG_ALLPUT,
							GF_PRINTCOLOR_MAKE(1, 2, 0), NULL );
		GF_STR_PrintColor(	&wk->msgwin_s, FONT_SYSTEM, msg_str, text_x, text_y, MSG_ALLPUT,
							GF_PRINTCOLOR_MAKE(1, 2, 0), NULL );
	}

	// つれあるき以外
	if( wk->type != SYOUJYOU_TYPE_PAIR )
	{// フッタの表示
		MSGMAN_GetString( wk->msgman, msg_l02r0301_award_04, msg_str );
		GF_STR_PrintColor(	&wk->msgwin_m, FONT_SYSTEM, msg_str, 138, 144, MSG_ALLPUT,
							GF_PRINTCOLOR_MAKE(1, 2, 0), NULL );
		GF_STR_PrintColor(	&wk->msgwin_s, FONT_SYSTEM, msg_str, 138, 144, MSG_ALLPUT,
							GF_PRINTCOLOR_MAKE(1, 2, 0), NULL );
	}

	STRBUF_Delete( msg_str );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	CAPを追加
 *
 *	@param	CATS_SYS_PTR csp
 *	@param	crp
 *	@param	pos_x
 *	@param	pos_y
 *	@param	anm
 *	@param	pri
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static CATS_ACT_PTR OBJ_AddStatus( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 pos_x, s16 pos_y, u8 anm, u8 pri )
{
	TCATS_OBJECT_ADD_PARAM_S prm = {
		0, 0, 0,
		0, 0, TCATS_ADD_S_PAL_AUTO, NNS_G2D_VRAM_TYPE_MAX,
		{ CHR_ID_STATUS, PAL_ID_STATUS, CEL_ID_STATUS, ANM_ID_STATUS, 0, 0 }, OBJ_BGPRI, FALSE,
	};

	CATS_ACT_PTR cap;

	prm.x = pos_x;
	prm.y = pos_y;
	prm.pri = pri;
	prm.anm = anm;

	cap = CATS_ObjectAdd_S_SubDistance( csp, crp, &prm, OBJ_DISTANCE );
	CATS_ObjectAutoAnimeSetCap( cap, FALSE );

	return cap;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ポケOBJ追加
 *
 *	@param	CATS_SYS_PTR csp
 *	@param	crp
 *	@param	px
 *	@param	py
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static CATS_ACT_PTR OBJ_AddPoke( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 px, s16 py )
{
	TCATS_OBJECT_ADD_PARAM_S prm = {
		0, 0, 0,
		0, PRI_POKE, PALOFS_POKE, NNS_G2D_VRAM_TYPE_MAX,
		{ CHR_ID_POKE, PAL_ID_POKE, CEL_ID_POKE, ANM_ID_POKE, 0, 0 }, OBJ_BGPRI, FALSE,
	};

	CATS_ACT_PTR cap;

	prm.x = px;
	prm.y = py;

	cap = CATS_ObjectAdd_S_SubDistance( csp, crp, &prm, OBJ_DISTANCE );

	return cap;
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	CATS_SYS_PTR csp
 *	@param	crp
 *	@param	px
 *	@param	py
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static CATS_ACT_PTR OBJ_AddHero( CATS_SYS_PTR csp, CATS_RES_PTR crp, s16 px, s16 py )
{
	TCATS_OBJECT_ADD_PARAM_S prm = {
		0, 0, 0,
		0, PRI_CMN, PALOFS_HERO, NNS_G2D_VRAM_TYPE_MAX,
		{ CHR_ID_HERO, PAL_ID_HERO, CEL_ID_HERO, ANM_ID_HERO, 0, 0 }, OBJ_BGPRI, FALSE,
	};

	CATS_ACT_PTR cap;

	prm.x = px;
	prm.y = py;

	cap = CATS_ObjectAdd_S_SubDistance( csp, crp, &prm, OBJ_DISTANCE );

	return cap;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ初期化
 *
 *	@param	SYOUJYOU_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Init( SYOUJYOU_WORK* wk )
{
	wk->csp = CATS_AllocMemory( wk->heapID );
	wk->crp = CATS_ResourceCreate( wk->csp );

	{
		TCATS_OAM_INIT	coi = {
			0, 128,
			0, 32,
			0, 128,
			0, 32,
		};

		TCATS_CHAR_MANAGER_MAKE ccmm = {
			0,	// dummy
			1024*128,
			1024*16,
			GX_OBJVRAMMODE_CHAR_1D_32K,
			GX_OBJVRAMMODE_CHAR_1D_32K,
		};

		ccmm.num = OBJ_NUM;

		CATS_SystemInit( wk->csp, &coi, &ccmm, 32 );
	}

	CATS_ClactSetInit( wk->csp, wk->crp, OBJ_NUM );

	{
		TCATS_RESOURCE_NUM_LIST crnl = { CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0 };
		CATS_ResourceManagerInit( wk->csp, wk->crp, &crnl );
	}

	//サブサーフェースの距離を設定
	CLACT_U_SetSubSurfaceMatrix( CATS_EasyRenderGet( wk->csp ), 0, OBJ_DISTANCE );


	// アーカイブから画像サイズを取得
	{
		DEBUG_POKE_INFO debug_info;
		int MonsNo = PokeParaGet( wk->poke, ID_PARA_monsno, NULL );
		int info_idx = PairPokeIdx_GetIdx( MonsNo );

		ArchiveDataLoad(&debug_info, ARC_PAIR_POKE_INFO, info_idx);

		// サイズを保持
		wk->BigSize = debug_info.BigSize;
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJ開放
 *
 *	@param	SYOUJYOU_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_Delete( SYOUJYOU_WORK* wk )
{
	CATS_SYS_PTR csp = wk->csp;
	CATS_RES_PTR crp = wk->crp;
	int i;

	for( i=0; i<CAP_ID_MAX; i++ )
	{
		GF_ASSERT( wk->cap[i] );

		CATS_ActorPointerDelete_S( wk->cap[i] );
	}

	CATS_ResourceDestructor_S(csp, crp);
	CATS_FreeMemory(csp);
}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJリソースロード
 *
 *	@param	SYOUJYOU_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_LoadRes( SYOUJYOU_WORK* wk )
{
	ARCHANDLE* arc;
	CATS_SYS_PTR csp = wk->csp;
	CATS_RES_PTR crp = wk->crp;

	// --- CROWN ---
	arc = ArchiveDataHandleOpen( ARC_POKESTATUS_GRA, wk->heapID );

	CATS_LoadResourcePlttArcH( csp, crp, arc,
			NARC_pst2_gra_ps_sub_obj_NCLR, 0, 2, NNS_G2D_VRAM_TYPE_MAX, PAL_ID_STATUS );

	CATS_LoadResourceCharArcH( csp, crp, arc,
			NARC_pst2_gra_ps_sub_obj_NCGR, 0, NNS_G2D_VRAM_TYPE_MAX, CHR_ID_STATUS );

	CATS_LoadResourceCellArcH( csp, crp, arc,
			NARC_pst2_gra_ps_sub_obj_NCER, 0, CEL_ID_STATUS );

	CATS_LoadResourceCellAnmArcH( csp, crp, arc,
			NARC_pst2_gra_ps_sub_obj_NANR, 0, ANM_ID_STATUS );

	ArchiveDataHandleClose(arc);

	// --- HERO ---
	arc = ArchiveDataHandleOpen( ARC_SYOUJYOU, wk->heapID );

	CATS_LoadResourcePlttArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_MAX, PAL_ID_HERO );

	CATS_LoadResourceCharArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_4x4_NCGR, 0, NNS_G2D_VRAM_TYPE_MAX, CHR_ID_HERO );

	CATS_LoadResourceCellArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_4x4_NCER, 0, CEL_ID_HERO );

	CATS_LoadResourceCellAnmArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_4x4_NANR, 0, ANM_ID_HERO );

	// --- POKE ---
	CATS_LoadResourcePlttArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_MAX, PAL_ID_POKE );

	CATS_LoadResourceCharArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_4x4_NCGR + wk->BigSize*3, 0, NNS_G2D_VRAM_TYPE_MAX, CHR_ID_POKE );

	CATS_LoadResourceCellArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_4x4_NCER + wk->BigSize*3, 0, CEL_ID_POKE );

	CATS_LoadResourceCellAnmArcH( csp, crp, arc,
			NARC_syoujyou_obj_dummy_4x4_NANR + wk->BigSize*3, 0, ANM_ID_POKE );

	ArchiveDataHandleClose(arc);

	//-------------------------------------------
	// Make Actor
	//-------------------------------------------
	wk->cap[ CAP_ID_CROWN ] = OBJ_AddStatus( wk->csp, wk->crp, g_OBJPos[0][0], g_OBJPos[1][1], OBJ_CROWN_ANM, PRI_CMN );
	wk->cap[ CAP_ID_HERO ] = OBJ_AddHero( wk->csp, wk->crp, g_OBJPos[1][0], g_OBJPos[1][1] );
	wk->cap[ CAP_ID_POKE ] = OBJ_AddPoke( wk->csp, wk->crp, g_OBJPos[2][0], g_OBJPos[2][1] );

	// 王冠は不必要になったので非表示
	CATS_ObjectEnableCap( wk->cap[ CAP_ID_CROWN ], CATS_ENABLE_FALSE );

	// 転送
	CLACT_HeroTrans( wk->cap[ CAP_ID_HERO ]->act, wk->my, wk->heapID );
	OBJ_PokeTrans( wk->cap[ CAP_ID_POKE ]->act, wk->poke, wk->heapID, wk->BigSize );

	GF_Disp_GX_VisibleControl(  GX_PLANEMASK_OBJ, VISIBLE_ON );		// MAIN DISP OBJ ON
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// SUB DISP OBJ ON
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	SYOUJYOU_WORK* wk
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_ScrollSet( SYOUJYOU_WORK* wk )
{
	int i;

	for( i=0; i<CAP_ID_MAX; i++ )
	{
		s16 px, py;

		GF_ASSERT( wk->cap[i] );

		px = g_OBJPos[i][0];
		py = g_OBJPos[i][1];

//		HOSAKA_PRINT( "[%d] get pos{%d,%d} + scroll:%d \n", i, px, py, wk->scroll*-1 );
		CATS_ObjectPosSetCap_SubSurface( wk->cap[i], px, py + wk->scroll*-1, OBJ_DISTANCE );
	}

}

//-----------------------------------------------------------------------------
/**
 *	@brief	OBJに割り当てられているキャラデータ（CGX）を書き換える
 *
 *	@param	CLACT_WORK_PTR act
 *	@param	* buf
 *	@param	siz
 *	@param	VramOfs
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void OBJ_CgxChangeTransShiftVramOfs( CLACT_WORK_PTR act, u8 * buf, u32 siz, u32 VramOfs )
{
	NNSG2dImageProxy * ipc;
	u32	cgx;
	NNS_G2D_VRAM_TYPE vram_type;

	vram_type = CLACT_VramTypeGet( act );

	// MAX専用
	GF_ASSERT( vram_type == NNS_G2D_VRAM_TYPE_MAX );

	DC_FlushRange( buf, siz );

	ipc = CLACT_ImageProxyGet( act );

	cgx = NNS_G2dGetImageLocation( ipc, NNS_G2D_VRAM_TYPE_2DMAIN );
	cgx += VramOfs;
	GX_LoadOBJ( buf, cgx, siz );

	cgx = NNS_G2dGetImageLocation( ipc, NNS_G2D_VRAM_TYPE_2DSUB );
	cgx += VramOfs;
	GXS_LoadOBJ( buf, cgx, siz );
}

//-----------------------------------------------------------------------------
/**
 *	@brief	CLACTの参照先CGXにマップキャラのグラフィックを展開
 *
 *	@param	CLACT_WORK_PTR act
 *	@param	tex_idx
 *	@param	ptn_ofs
 *	@param	HeapID
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CLACT_MapModelTrans( CLACT_WORK_PTR act, u32 tex_idx, u8 ptn_ofs, HEAPID HeapID )
{
	enum {
		TRANS_PAL_SIZE = 16*2,
		TRANS_CHR_X = 4,
		TRANS_CHR_Y = 4,
		TRANS_SIZE = TRANS_CHR_X * TRANS_CHR_Y * 0x20,
	};

	u32				i;
	ARCHANDLE*		arc;
	NNSG3dResTex*	pTex;
	void*			pFile;
	u8*				pStart;
	void*			pRawData;

	// 非表示にしておく
	CATS_ObjectEnable( act, FALSE );

	//トレーナーデータのアーカイブオープン
	arc = ArchiveDataHandleOpen( ARC_MMODEL, HeapID );

	// テクスチャファイルを取得
	pFile = ArchiveDataLoadAllocByHandle( arc, tex_idx ,HeapID );
	pTex = NNS_G3dGetTex( (NNSG3dResFileHeader*)pFile );

	//テクスチャロウデータ取得
	{
		void* pBuf;

		HOSAKA_PRINT( "tex size = %d \n", pTex->texInfo.sizeTex );

		pStart = (u8*)pTex + pTex->texInfo.ofsTex;

		pBuf = sys_AllocMemoryLo( HeapID, TRANS_SIZE );

		pRawData = &pStart[ TRANS_SIZE * ptn_ofs ];
		ChangesInto_RawData_1D_from_2D( pRawData, TRANS_CHR_X, 0, 0, TRANS_CHR_X, TRANS_CHR_Y, pBuf );
		OBJ_CgxChangeTransShiftVramOfs( act, pBuf, TRANS_SIZE, 0 );

		sys_FreeMemoryEz( pBuf );
	}

	//パレットロウデータ取得
	{
		NNSG2dImagePaletteProxy* ipp;
		NNS_G2D_VRAM_TYPE type;
		u32 vram;

		type = CLACT_VramTypeGet( act );

		pStart = (u8*)pTex + pTex->plttInfo.ofsPlttData;
		DC_FlushRange( pStart, TRANS_PAL_SIZE );

		ipp = CLACT_PaletteProxyGet( act );

	/*
		// なんでか0番に転送される。。。
		// 両面転送
		vram = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );
		GX_LoadOBJPltt( pStart, vram, TRANS_PAL_SIZE );
		vram = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DSUB );
		GXS_LoadOBJPltt( pStart, vram, TRANS_PAL_SIZE );
	*/

		// 直接転送
		GX_LoadOBJPltt( pStart, PALOFS_HERO*0x20, TRANS_PAL_SIZE );
		GXS_LoadOBJPltt( pStart, PALOFS_HERO*0x20, TRANS_PAL_SIZE );

	}

	// -- 開放処理 --
	sys_FreeMemoryEz( pFile );
	ArchiveDataHandleClose( arc );

	// 表示
	CATS_ObjectEnable( act, TRUE );
}

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	CLACT_WORK_PTR act
 *	@param	my
 *	@param	heapID
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void CLACT_HeroTrans( CLACT_WORK_PTR act, MYSTATUS* my, HEAPID heapID )
{
	u32 tex_idx;

	// 男女判定
	if ( MyStatus_GetMySex( my ) == PM_MALE ) {
		tex_idx = NARC_mmodel_hero_nsbtx;
	} else {
		tex_idx = NARC_mmodel_heroine_nsbtx;
	}

	CLACT_MapModelTrans( act, tex_idx, 21, heapID );
}

//--------------------------------------------------------------
/**
 * 連れ歩きポケモンのアーカイブインデックスを返す
 * @param	inMonsNo	モンスターナンバー
 * @param	inFormNo	フォルムナンバー
 * @param	inSex		性別
 *
 * @retval	idx			アーカイブインデックス
 */
//--------------------------------------------------------------
static int GetMonsArcIdx(const int inMonsNo, const u16 inFormNo, const int inSex)
{
	int idx;
	if ( (inMonsNo<=0) || (MONSNO_END<inMonsNo) ){
		idx = 1;
	}else{
		idx = NARC_mmodel_tsure_001_nsbtx + PairPokeIdx_GetIdx(inMonsNo);
		//モンスターナンバーだけからだと不十分なので、ここからさらに調べる（フォルムとか）
		//性別による描き違いをして、かつ複数フォルムナンバー所持ポケモンはいないので、
		//性別違いをまずキーにして分岐
		if (PairPokeIdx_GetSexDif(inMonsNo)){		//性別による描き違いがある
			if(inSex == PARA_FEMALE ){ //メスの場合
				idx += 1;	//ベースから1シフトしたところがメスのコード
			}
		}else{		//性別による描き違いがない
			//フォルムを調べる
			int form;
			if ( inFormNo > PairPokeIdx_GetFormNum(inMonsNo) ){
				form = 0;
			}else{
				form = inFormNo;
			}
			idx += form;
		}
	}
	return idx;
}


//-----------------------------------------------------------------------------
/**
 *	@brief	ポケモンのグラフィックを転送/表示
 */
//-----------------------------------------------------------------------------
static void OBJ_PokeTrans( CLACT_WORK_PTR act, POKEMON_PARAM* poke, HEAPID HeapID, BOOL b_bigsize )
{
	enum { POKE_PLTT_SIZE = 16*2 };

	int MonsNo;
	int Form;
	u8 Sex;
	u8 Rare;

	int trans_size;
	u8 size_w, size_h;

	ARCHANDLE* arc;
	void* pFile;
	NNSG3dResTex* pTex;

	MonsNo = PokeParaGet( poke, ID_PARA_monsno, NULL );
	Form = PokeParaGet( poke, ID_PARA_form_no, NULL );
	Sex = PokeSexGet( poke );
	Rare = PokeRareGet( poke );

	HOSAKA_PRINT("trans poke MonsNo:%d Form:%d Sex:%d Rare:%d \n",MonsNo, Form, Sex, Rare );

	// サイズからトランスサイズ、対象アクターを決定
	if( b_bigsize )
	{
		trans_size = 64 * 64 / 2;
		size_w = 8;
		size_h = 8;
	}
	else
	{
		trans_size = 32 * 32 / 2;
		size_w = 4;
		size_h = 4;
	}

	// マップモデルのアーカイブオープン
	arc = ArchiveDataHandleOpen( ARC_MMODEL, HeapID );

	// キャラ転送
	{
		int arc_idx;
		u8 *pStart;
		void* pRawData;
		void* pCharTempBuff;

		// フォルムチェック
		if( PokeFuseiFormNoCheck( MonsNo, Form ) == FALSE )
		{
			// 金銀に存在しないフォルムの場合、デフォルトフォルムを表示
			Form = 0;
		}

		//アーカイブインデックス取得
		arc_idx = GetMonsArcIdx(MonsNo, Form, Sex);
		//連れ歩きポケモンのテクスチャを読み込んでくる
		pFile = ArchiveDataLoadAllocByHandle( arc, arc_idx, HeapID );
		// テクスチャファイルを取得
		pTex = NNS_G3dGetTex( (NNSG3dResFileHeader*)pFile );

		// テクスチャロウデータ取得
		pStart = (u8*)pTex + pTex->texInfo.ofsTex;
		HOSAKA_PRINT("texsize= %x\n", pTex->texInfo.sizeTex );

		// キャラ保持用テンポラリバッファを生成
		pCharTempBuff = sys_AllocMemoryLo( HeapID, trans_size );

		pRawData = &pStart[ trans_size * OBJ_TEXANM_POKE_OFS ];
		ChangesInto_RawData_1D_from_2D( pRawData, size_w, 0, 0, size_w, size_h, pCharTempBuff );
		OBJ_CgxChangeTransShiftVramOfs( act, pCharTempBuff, trans_size, 0 );

		sys_FreeMemoryEz( pCharTempBuff );
	}

	// パレット転送
#if 1
	{
		NNSG2dImagePaletteProxy* ipp;
		NNS_G2D_VRAM_TYPE type;
		u32 vram;
		u8* pStart;

		type = CLACT_VramTypeGet(act);
		pStart = (u8*)pTex + pTex->plttInfo.ofsPlttData;

		// レアだったらオフセット変更
		if( Rare )
		{
			pStart = &pStart[ POKE_PLTT_SIZE ];
		}

		DC_FlushRange( pStart, POKE_PLTT_SIZE );

		ipp = CLACT_PaletteProxyGet(act);

		// 直接転送
		GX_LoadOBJPltt( pStart, PALOFS_POKE*0x20, POKE_PLTT_SIZE );
		GXS_LoadOBJPltt( pStart, PALOFS_POKE*0x20, POKE_PLTT_SIZE );
	}
#endif

	// 開放処理
	sys_FreeMemoryEz( pFile );
	ArchiveDataHandleClose( arc );

	// 表示
	CATS_ObjectEnable( act, TRUE );
}
